package com.sinopec.basemodule.resultcontract

import android.os.Bundle
import android.os.Parcelable

/**
 * 核心 getset设置
 */
interface BundleAble<T> {
    fun get(bundle: Bundle?): T?
    fun set(t: T?, bundle: Bundle)

    object Unit : BundleAble<kotlin.Unit> {
        override fun get(bundle: Bundle?) {
        }

        override fun set(t: kotlin.Unit?, bundle: Bundle) {
        }
    }

    object Int : BundleAble<kotlin.Int> {
        override fun get(bundle: Bundle?): kotlin.Int? {
            return bundle?.getInt("params", -1)
        }

        override fun set(t: kotlin.Int?, bundle: Bundle) {
            bundle.putInt("params", t!!)
        }

    }

    object String : BundleAble<kotlin.String> {
        override fun get(bundle: Bundle?): kotlin.String? {
            return bundle?.getString("params")
        }

        override fun set(t: kotlin.String?, bundle: Bundle) {
            bundle.putString("params", t!!)
        }
    }

    object Boolean : BundleAble<kotlin.Boolean> {
        override fun get(bundle: Bundle?): kotlin.Boolean? {
            return bundle?.getBoolean("params", false) ?: false
        }

        override fun set(t: kotlin.Boolean?, bundle: Bundle) {
            bundle.putBoolean("params", t ?: false)
        }
    }

    class Parcelables<T : Parcelable> : BundleAble<T> {
        override fun get(bundle: Bundle?): T? {
            return bundle?.getParcelable("params")
        }

        override fun set(t: T?, bundle: Bundle) {
            bundle.putParcelable("params", t)
        }
    }


}
